summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
ca8b854)
Sequences for writing or reading lists to/from files are moved to the
stgit.utils file.
Signed-off-by: Catalin Marinas <catalin.marinas@gmail.com>
def get_applied(self):
if not os.path.isfile(self.__applied_file):
raise StackException, 'Branch "%s" not initialised' % self.__name
def get_applied(self):
if not os.path.isfile(self.__applied_file):
raise StackException, 'Branch "%s" not initialised' % self.__name
- f = file(self.__applied_file)
- names = [line.strip() for line in f.readlines()]
- f.close()
- return names
+ return read_strings(self.__applied_file)
def get_unapplied(self):
if not os.path.isfile(self.__unapplied_file):
raise StackException, 'Branch "%s" not initialised' % self.__name
def get_unapplied(self):
if not os.path.isfile(self.__unapplied_file):
raise StackException, 'Branch "%s" not initialised' % self.__name
- f = file(self.__unapplied_file)
- names = [line.strip() for line in f.readlines()]
- f.close()
- return names
+ return read_strings(self.__unapplied_file)
def get_hidden(self):
if not os.path.isfile(self.__hidden_file):
return []
def get_hidden(self):
if not os.path.isfile(self.__hidden_file):
return []
- f = file(self.__hidden_file)
- names = [line.strip() for line in f.readlines()]
- f.close()
- return names
+ return read_strings(self.__hidden_file)
def get_base(self):
# Return the parent of the bottommost patch, if there is one.
def get_base(self):
# Return the parent of the bottommost patch, if there is one.
self.log_patch(patch, 'new')
patches = [patch.get_name()] + self.get_unapplied()
self.log_patch(patch, 'new')
patches = [patch.get_name()] + self.get_unapplied()
-
- f = file(self.__unapplied_file, 'w+')
- f.writelines([line + '\n' for line in patches])
- f.close()
+ write_strings(self.__unapplied_file, patches)
elif before_existing:
self.log_patch(patch, 'new')
elif before_existing:
self.log_patch(patch, 'new')
unapplied = self.get_unapplied()
unapplied.remove(name)
unapplied = self.get_unapplied()
unapplied.remove(name)
- f = file(self.__unapplied_file, 'w+')
- f.writelines([line + '\n' for line in unapplied])
- f.close()
+ write_strings(self.__unapplied_file, unapplied)
def forward_patches(self, names):
"""Try to fast-forward an array of patches.
def forward_patches(self, names):
"""Try to fast-forward an array of patches.
git.switch(top)
append_strings(self.__applied_file, names[0:forwarded])
git.switch(top)
append_strings(self.__applied_file, names[0:forwarded])
-
- f = file(self.__unapplied_file, 'w+')
- f.writelines([line + '\n' for line in unapplied])
- f.close()
+ write_strings(self.__unapplied_file, unapplied)
append_string(self.__applied_file, name)
unapplied.remove(name)
append_string(self.__applied_file, name)
unapplied.remove(name)
- f = file(self.__unapplied_file, 'w+')
- f.writelines([line + '\n' for line in unapplied])
- f.close()
+ write_strings(self.__unapplied_file, unapplied)
# head == bottom case doesn't need to refresh the patch
if empty or head != bottom:
# head == bottom case doesn't need to refresh the patch
if empty or head != bottom:
popped = applied[:idx]
popped.reverse()
unapplied = popped + self.get_unapplied()
popped = applied[:idx]
popped.reverse()
unapplied = popped + self.get_unapplied()
-
- f = file(self.__unapplied_file, 'w+')
- f.writelines([line + '\n' for line in unapplied])
- f.close()
+ write_strings(self.__unapplied_file, unapplied)
del applied[:idx]
applied.reverse()
del applied[:idx]
applied.reverse()
-
- f = file(self.__applied_file, 'w+')
- f.writelines([line + '\n' for line in applied])
- f.close()
+ write_strings(self.__applied_file, applied)
def empty_patch(self, name):
"""Returns True if the patch is empty
def empty_patch(self, name):
"""Returns True if the patch is empty
if oldname in unapplied:
Patch(oldname, self.__patch_dir, self.__refs_dir).rename(newname)
unapplied[unapplied.index(oldname)] = newname
if oldname in unapplied:
Patch(oldname, self.__patch_dir, self.__refs_dir).rename(newname)
unapplied[unapplied.index(oldname)] = newname
-
- f = file(self.__unapplied_file, 'w+')
- f.writelines([line + '\n' for line in unapplied])
- f.close()
+ write_strings(self.__unapplied_file, unapplied)
elif oldname in applied:
Patch(oldname, self.__patch_dir, self.__refs_dir).rename(newname)
applied[applied.index(oldname)] = newname
elif oldname in applied:
Patch(oldname, self.__patch_dir, self.__refs_dir).rename(newname)
applied[applied.index(oldname)] = newname
-
- f = file(self.__applied_file, 'w+')
- f.writelines([line + '\n' for line in applied])
- f.close()
+ write_strings(self.__applied_file, applied)
else:
raise StackException, 'Unknown patch "%s"' % oldname
else:
raise StackException, 'Unknown patch "%s"' % oldname
append_string(self.__hidden_file, name)
unapplied.remove(name)
append_string(self.__hidden_file, name)
unapplied.remove(name)
- f = file(self.__unapplied_file, 'w+')
- f.writelines([line + '\n' for line in unapplied])
- f.close()
+ write_strings(self.__unapplied_file, unapplied)
def unhide_patch(self, name):
"""Remove the patch from the hidden list.
def unhide_patch(self, name):
"""Remove the patch from the hidden list.
raise StackException, 'Unknown patch "%s"' % name
hidden.remove(name)
raise StackException, 'Unknown patch "%s"' % name
hidden.remove(name)
- f = file(self.__hidden_file, 'w+')
- f.writelines([line + '\n' for line in hidden])
- f.close()
+ write_strings(self.__hidden_file, hidden)
if not self.patch_applied(name) and not self.patch_unapplied(name):
# check needed for backward compatibility with the old
if not self.patch_applied(name) and not self.patch_unapplied(name):
# check needed for backward compatibility with the old
create_dirs(os.path.dirname(filename))
return file(filename, mode)
create_dirs(os.path.dirname(filename))
return file(filename, mode)
+def read_strings(filename):
+ """Reads the lines from a file
+ """
+ f = file(filename, 'r')
+ lines = [line.strip() for line in f.readlines()]
+ f.close()
+ return lines
+
def read_string(filename, multiline = False):
"""Reads the first line from a file
"""
def read_string(filename, multiline = False):
"""Reads the first line from a file
"""
+def write_strings(filename, lines):
+ """Write 'lines' sequence to file
+ """
+ f = file(filename, 'w+')
+ f.writelines([line + '\n' for line in lines])
+ f.close()
+
def write_string(filename, line, multiline = False):
"""Writes 'line' to file and truncates it
"""
def write_string(filename, line, multiline = False):
"""Writes 'line' to file and truncates it
"""