##// END OF EJS Templates
dirstate-item: feed more information to `__init__`...
marmoute -
r48706:22c39f8a default
parent child Browse files
Show More
@@ -65,21 +65,100 b' static PyObject *dirstate_item_new(PyTyp'
65 65 /* We do all the initialization here and not a tp_init function because
66 66 * dirstate_item is immutable. */
67 67 dirstateItemObject *t;
68 char state;
69 int size, mode, mtime;
70 if (!PyArg_ParseTuple(args, "ciii", &state, &mode, &size, &mtime)) {
68 int wc_tracked;
69 int p1_tracked;
70 int p2_tracked;
71 int merged;
72 int clean_p1;
73 int clean_p2;
74 int possibly_dirty;
75 PyObject *parentfiledata;
76 static char *keywords_name[] = {
77 "wc_tracked", "p1_tracked", "p2_tracked",
78 "merged", "clean_p1", "clean_p2",
79 "possibly_dirty", "parentfiledata", NULL,
80 };
81 wc_tracked = 0;
82 p1_tracked = 0;
83 p2_tracked = 0;
84 merged = 0;
85 clean_p1 = 0;
86 clean_p2 = 0;
87 possibly_dirty = 0;
88 parentfiledata = Py_None;
89 if (!PyArg_ParseTupleAndKeywords(args, kwds, "iiiiiiiO", keywords_name,
90 &wc_tracked, &p1_tracked, &p2_tracked,
91 &merged, &clean_p1, &clean_p2,
92 &possibly_dirty, &parentfiledata
93
94 )) {
71 95 return NULL;
72 96 }
73
97 if (merged && (clean_p1 || clean_p2)) {
98 PyErr_SetString(PyExc_RuntimeError,
99 "`merged` argument incompatible with "
100 "`clean_p1`/`clean_p2`");
101 return NULL;
102 }
74 103 t = (dirstateItemObject *)subtype->tp_alloc(subtype, 1);
75 104 if (!t) {
76 105 return NULL;
77 106 }
78 t->state = state;
79 t->mode = mode;
80 t->size = size;
81 t->mtime = mtime;
82
107 t->state = 'r';
108 t->mode = 0;
109 t->size = dirstate_v1_nonnormal;
110 t->mtime = ambiguous_time;
111 if (!(p1_tracked || p2_tracked || wc_tracked)) {
112 /* Nothing special to do, file is untracked */
113 } else if (merged) {
114 t->state = 'm';
115 t->size = dirstate_v1_from_p2;
116 t->mtime = ambiguous_time;
117 } else if (!(p1_tracked || p2_tracked) && wc_tracked) {
118 t->state = 'a';
119 t->size = dirstate_v1_nonnormal;
120 t->mtime = ambiguous_time;
121 } else if ((p1_tracked || p2_tracked) && !wc_tracked) {
122 t->state = 'r';
123 t->size = 0;
124 t->mtime = 0;
125 } else if (clean_p2 && wc_tracked) {
126 t->state = 'n';
127 t->size = dirstate_v1_from_p2;
128 t->mtime = ambiguous_time;
129 } else if (!p1_tracked && p2_tracked && wc_tracked) {
130 t->state = 'n';
131 t->size = dirstate_v1_from_p2;
132 t->mtime = ambiguous_time;
133 } else if (possibly_dirty) {
134 t->state = 'n';
135 t->size = dirstate_v1_nonnormal;
136 t->mtime = ambiguous_time;
137 } else if (wc_tracked) {
138 /* this is a "normal" file */
139 if (parentfiledata == Py_None) {
140 PyErr_SetString(
141 PyExc_RuntimeError,
142 "failed to pass parentfiledata for a normal file");
143 return NULL;
144 }
145 if (!PyTuple_CheckExact(parentfiledata)) {
146 PyErr_SetString(
147 PyExc_TypeError,
148 "parentfiledata should be a Tuple or None");
149 return NULL;
150 }
151 t->state = 'n';
152 t->mode =
153 (int)PyLong_AsLong(PyTuple_GetItem(parentfiledata, 0));
154 t->size =
155 (int)PyLong_AsLong(PyTuple_GetItem(parentfiledata, 1));
156 t->mtime =
157 (int)PyLong_AsLong(PyTuple_GetItem(parentfiledata, 2));
158 } else {
159 PyErr_SetString(PyExc_RuntimeError, "unreachable");
160 return NULL;
161 }
83 162 return (PyObject *)t;
84 163 }
85 164
@@ -61,11 +61,62 b' class DirstateItem(object):'
61 61 _size = attr.ib()
62 62 _mtime = attr.ib()
63 63
64 def __init__(self, state, mode, size, mtime):
65 self._state = state
66 self._mode = mode
67 self._size = size
68 self._mtime = mtime
64 def __init__(
65 self,
66 wc_tracked=False,
67 p1_tracked=False,
68 p2_tracked=False,
69 merged=False,
70 clean_p1=False,
71 clean_p2=False,
72 possibly_dirty=False,
73 parentfiledata=None,
74 ):
75 if merged and (clean_p1 or clean_p2):
76 msg = b'`merged` argument incompatible with `clean_p1`/`clean_p2`'
77 raise error.ProgrammingError(msg)
78
79 self._state = None
80 self._mode = 0
81 self._size = NONNORMAL
82 self._mtime = AMBIGUOUS_TIME
83 if not (p1_tracked or p2_tracked or wc_tracked):
84 pass # the object has no state to record
85 elif merged:
86 self._state = b'm'
87 self._size = FROM_P2
88 self._mtime = AMBIGUOUS_TIME
89 elif not (p1_tracked or p2_tracked) and wc_tracked:
90 self._state = b'a'
91 self._size = NONNORMAL
92 self._mtime = AMBIGUOUS_TIME
93 elif (p1_tracked or p2_tracked) and not wc_tracked:
94 self._state = b'r'
95 self._size = 0
96 self._mtime = 0
97 elif clean_p2 and wc_tracked:
98 self._state = b'n'
99 self._size = FROM_P2
100 self._mtime = AMBIGUOUS_TIME
101 elif not p1_tracked and p2_tracked and wc_tracked:
102 self._state = b'n'
103 self._size = FROM_P2
104 self._mtime = AMBIGUOUS_TIME
105 elif possibly_dirty:
106 self._state = b'n'
107 self._size = NONNORMAL
108 self._mtime = AMBIGUOUS_TIME
109 elif wc_tracked:
110 # this is a "normal" file
111 if parentfiledata is None:
112 msg = b'failed to pass parentfiledata for a normal file'
113 raise error.ProgrammingError(msg)
114 self._state = b'n'
115 self._mode = parentfiledata[0]
116 self._size = parentfiledata[1]
117 self._mtime = parentfiledata[2]
118 else:
119 assert False, 'unreachable'
69 120
70 121 @classmethod
71 122 def from_v1_data(cls, state, mode, size, mtime):
@@ -74,12 +125,12 b' class DirstateItem(object):'
74 125 Since the dirstate-v1 format is frozen, the signature of this function
75 126 is not expected to change, unlike the __init__ one.
76 127 """
77 return cls(
78 state=state,
79 mode=mode,
80 size=size,
81 mtime=mtime,
82 )
128 instance = cls()
129 instance._state = state
130 instance._mode = mode
131 instance._size = size
132 instance._mtime = mtime
133 return instance
83 134
84 135 def set_possibly_dirty(self):
85 136 """Mark a file as "possibly dirty"
General Comments 0
You need to be logged in to leave comments. Login now